home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7661 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: news.indy.net!amphigory!pazuzu
  2. From: Pazuzu@amphigory.com (Pazuzu)
  3. Date: 27 Feb 96 20:16:46 
  4. Newsgroups: comp.lang.c
  5. Subject: What is &Variable (declared as: char Var
  6. Message-ID: <13b_9602272020@amphigory.com>
  7. Organization: The Vision and the Void
  8.  
  9. On 2/25/96  5:53PM, Fido wrote:
  10.  
  11. >From: Abu Wawda
  12. >To: All
  13. >Subject: What is &Variable (declared as: char Variable[10])?
  14. >Date: 25 Feb 96  17:53:53
  15.  
  16. >From: wawda@alcor.usc.edu (Abu Wawda)
  17. >Subject: What is &Variable (declared as: char Variable[10])?
  18. >Organization: University of Southern California, Los Angeles, CA
  19.  
  20. >I'm having trouble understanding what the address of a static array
  21. >is. For example, if I declare a variable called myarray as:
  22. >    char myarray[10];
  23. >then what could &myarray possibly mean? myarray is not a pointer, so
  24. >&myarray could not possibly be the address of the variable myarray
  25. >(like it would be if I did char* myarray and then asked for &myarray).
  26.  
  27. >Functions such as scanf() allow the following:
  28.  
  29. >    char myarray[10];
  30.  
  31. >    scanf("%s",&myarray);
  32.  
  33. >but I don't understand what scanf() could possibly be taking in the
  34. >second parameter. It can't be: char** since myarray is not a
  35. >pointer. I CAN understand how the following would work:
  36.  
  37.  
  38. myarray may not be a pointer (actually, it IS, but for the sake of argument...)
  39. but EVERYTHING, EVERYTHING, EVERYTHING has a memory address (otheriwise, it
  40. ain't in memory!), and &<identifier> gives you its address.  myarray IS a
  41. pointer. All arrays are pointers.
  42.  
  43. >I cannot pass &myarray if I declare it as: char myarray[10]. So how do
  44. >this work? Thanks in advance,
  45.  
  46. >Abu Wawda
  47. >wawda@scf.usc.edu
  48.  
  49. Yes, you can pass it.  here:
  50.  
  51. void func1(char *blort) {
  52.     printf("%s", blort);
  53. }
  54.  
  55. void func2(void) {
  56.     char astring[81];
  57.     strcpy(astring, "this is a test...");
  58.     func1(&astring);
  59. }
  60.  
  61. ---
  62. Pazuzu (pazuzu@amphigory.com):
  63.    SysOp: The Vision and the Void - +1 219 583 5786 - 2400 - 28,800 24/7
  64.     Running Excalibur & WME / BeeMail Alpha Site - h/p, Law, Drugs, Etc
  65. --- home page: http://www.beemail.com/pazuzu ---
  66. GothCode 2.0: GoCS!4Ju!3 TJt cDBRc+3M PSl(R) V++s M++ ZGo(GnPuSkInExThBm) 
  67. C+4P15ucp a25+ n+O b:+T H180 g+T w+T r+3(-3)B D+4! h++ s10 k++BdSMDsWR Rm 
  68. Sm N1291LS LusIN- HfsSp8 
  69.